/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.Dao;
import java.sql.*;
import Model.Entity.BookEntity;
import Model.Dao.DataAccess;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Trung
 */
public class BookDao {
    
    public List<BookEntity> getAll(){
        DataAccess da = new DataAccess();
        List<BookEntity> listBook = new ArrayList<BookEntity>();
        try {
            da.ps = da.con.prepareCall("select * from BookInfo");
            da.rs = da.ps.executeQuery();
            while(da.rs.next()){
                
                listBook.add(new BookEntity(da.rs.getInt(1),da.rs.getString(2),da.rs.getDouble(4),da.rs.getString(3),da.rs.getString(5),da.rs.getInt(6)));
                
            }
            
            da.con.close();
        } catch (SQLException ex) {
            Logger.getLogger(BookDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return listBook;
    }
    
    public List<BookEntity> getAllId(String id){
        DataAccess da = new DataAccess();
        List<BookEntity> listBook = new ArrayList<BookEntity>();
        try {
            da.ps = da.con.prepareCall("select * from BookInfo where category = " + id);
            da.rs = da.ps.executeQuery();
            while(da.rs.next()){
                
                listBook.add(new BookEntity(da.rs.getInt(1),da.rs.getString(2),da.rs.getDouble(4),da.rs.getString(3),da.rs.getString(5),da.rs.getInt(6)));
                
            }
            
            da.con.close();
        } catch (SQLException ex) {
            Logger.getLogger(BookDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return listBook;
    }
    
    
}
